home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / EltNode-m < prev    next >
Encoding:
Text File  |  1994-11-18  |  3.4 KB  |  135 lines

  1. /* Code for implementation for Objective-C EltNode objects
  2.    Copyright (C) 1993 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@cs.rochester.edu>
  5.    Dept. of Computer Science, U. of Rochester, Rochester, NY  14627
  6.  
  7.    This file is part of the GNU Objective-C library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. /* This file gets included in all the ...EltNode.m files.
  25.    Doing this silly #include stuff is a poor substitute for multiple
  26.    inheritance.  sigh.
  27.  
  28.    Pattern:
  29.  
  30.    @implementation FooEltNode : FooNode
  31.    #include <objects/EltNode-m>
  32.    @end
  33. */
  34.  
  35. #include <objects/eltfuncs.h>
  36.  
  37. - initElement: (elt)anElement 
  38.     encoding: (const char *)eltEncoding
  39. {
  40.   [super init];
  41.   _element = anElement;
  42.   _elt_comparison_function = elt_get_comparison_function(eltEncoding);
  43.   return self;
  44. }
  45.  
  46. /* Archiving must mimic the above designated initializer */
  47.  
  48. - (void) encodeWithCoder: (Coder*)aCoder
  49. {
  50.   const char *encoding;
  51.  
  52.   [super encodeWithCoder:aCoder];
  53.   encoding = elt_get_encoding(_elt_comparison_function);
  54.   [aCoder encodeValueOfType:@encode(char*) at:&encoding 
  55.       withName:"EltNode Content Type Encoding"];
  56.   [aCoder encodeValueOfType:encoding 
  57.       at:elt_get_ptr_to_member(encoding, &_element)
  58.       withName:"EltNode Content Element"];
  59. }
  60.  
  61. - (elt*) _elementDataPtr
  62. {
  63.   return &_element;
  64. }
  65.  
  66. - (int(**)(elt,elt)) _eltComparisonFunctionPtr
  67. {
  68.   return &_elt_comparison_function;
  69. }
  70.  
  71. + newWithCoder: (Coder*)aCoder
  72. {
  73.   id n;
  74.   char *encoding;
  75.  
  76.   n = [super newWithCoder:aCoder];
  77.   [aCoder decodeValueOfType:@encode(char*)
  78.       at:&encoding
  79.       withName:NULL];
  80.   *[n _eltComparisonFunctionPtr] = elt_get_comparison_function(encoding);
  81.   [aCoder decodeValueOfType:encoding
  82.       at:[n _elementDataPtr]
  83.       withName:NULL];
  84.   return n;
  85. }
  86.  
  87. - write: (TypedStream*)aStream
  88. {
  89.   const char *encoding;
  90.  
  91.   [super write:aStream];
  92.   encoding = elt_get_encoding(_elt_comparison_function);
  93.   objc_write_type(aStream, @encode(char*), &encoding);
  94.   objc_write_types(aStream, encoding, 
  95.            elt_get_ptr_to_member(encoding, &_element));
  96.   return self;
  97. }
  98.  
  99. - read: (TypedStream*)aStream
  100. {
  101.   char *encoding;
  102.  
  103.   [super read:aStream];
  104.   objc_read_type(aStream, @encode(char*), &encoding);
  105.   _elt_comparison_function = elt_get_comparison_function(encoding);
  106.   objc_read_type(aStream, encoding, 
  107.          elt_get_ptr_to_member(encoding,&_element));
  108.   return self;
  109. }
  110.  
  111. - (int(*)(elt,elt)) comparisonFunction
  112. {
  113.   return _elt_comparison_function;
  114. }
  115.  
  116. - (elt) elementData
  117. {
  118.   return _element;
  119. }
  120.  
  121. - (int) compare: anotherObject
  122. {
  123.   /* perhaps we should do more checking first */
  124.   return _elt_comparison_function(_element, [anotherObject elementData]);
  125. }
  126.  
  127. - printForDebugger
  128. {
  129.   elt_fprintf_elt(stdout, 
  130.           elt_get_encoding(_elt_comparison_function),
  131.           _element);
  132.   printf("\n");
  133.   return self;
  134. }
  135.